#include "climate.h"
#include <map>


using namespace std;


static map<string, shared_ptr<Climate>> initNameMap();


map<unsigned int, shared_ptr<Climate>> Climate::colorMap;
map<string, shared_ptr<Climate>>       Climate::nameMap = initNameMap();


static map<string, shared_ptr<Climate>> initNameMap()
{
	map<string, shared_ptr<Climate>> map;

	shared_ptr<Climate> defaultClimate(new Climate());
	defaultClimate->name = "default";
	map[defaultClimate->name] = defaultClimate;

	return map;
}


Climate::Climate()
{
	memset(&textures, 0, sizeof(textures));
}

void Climate::add(shared_ptr<Climate> climate)
{
	colorMap[climate->color] = climate;
	nameMap[climate->name]   = climate;
}


shared_ptr<Climate> Climate::get(unsigned int color)
{
	shared_ptr<Climate> climate = colorMap[color];// & 0xffffff];
	if (climate == NULL)
	{
		climate = nameMap["default"];
	}
	return climate;
}


shared_ptr<Climate> Climate::getClimate(string name)
{
	return nameMap[name];
}

map<unsigned int, shared_ptr<Climate>>& Climate::getColorMap()
{
	return colorMap;
}